/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.ifal.supermercadobarateiro.bd;

import br.edu.ifal.supermercadobarateiro.modelo.Funcionario;
import br.edu.ifal.supermercadobarateiro.modelo.Login;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Mikaely Anaeve
 */
public class BdLogin {
  /*public void insere(Login l) throws SQLException {
        FabricaConexao fc = new FabricaConexao();
        Connection con = fc.abreConexao();

        String sql = "insert into login "
                + "(usuario,senha,) "
                + "values (?,?)";
        PreparedStatement stmt = con.prepareStatement(sql);
        stmt.setString(1, l.getUsuario());
        stmt.setString(2, l.getSenha());
        stmt.setInt(3, l.getId());
        
        stmt.execute();
        stmt.close();
        con.close();
    }*/
    public Funcionario busca(String senha) throws SQLException {
        FabricaConexao fc = new FabricaConexao();
        Connection con = fc.abreConexao();
        String sql = "select *from login where senha= ?";
        PreparedStatement stmt = con.prepareStatement(sql);
        stmt.setString(1, senha);
        ResultSet rs = stmt.executeQuery();
      Funcionario f = new Funcionario();
        while (rs.next()) {

            f.setEmail(rs.getString("email"));
            f.setSenha(rs.getString("senha"));
            


        }
        rs.close();
        stmt.close();
        con.close();
        return f;
    }
}
